<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发放编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="id" autocomplete="off" placeholder="请输入具体的编号"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsNo" placeholder="请输入具体的编号" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/provide/samples/list',
            method: 'GET',
            contentType: 'application/x-www-form-urlencoded',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],

            cols: [[
                {
                    field: 'numbering', title: '序号', width: 60, align: 'center', templet: function (d) {
                        return d.LAY_INDEX; //返回序号
                    }
                },
                {
                    field: 'id', title: '样品发放编号', minWidth: 120, align: 'center',
                    templet: function (d) {
                        return d.info?.id ?? '';
                    }
                },
                {
                    field: 'goodsName',
                    title: '商品名称',
                    align: 'center',
                    minWidth: 120,
                    templet: function (d) {
                        let goodsName = d.info?.goodsName ?? '';
                        let goodsNo = d.info?.goodsNo ?? '';
                        if (isNotNull(goodsName) && isNotNull(goodsNo)) {
                            return goodsName + '（' + goodsNo + '）';
                        }
                        return goodsName;
                    }
                },
                {
                    field: 'specification', title: '样品规格', minWidth: 120, align: 'center',
                    templet: function (d) {
                        return d.info?.specification ?? '';
                    }
                },
                {
                    field: 'samplePrice', title: '单价', minWidth: 100, align: 'center',
                    templet: function (d) {
                        return d.info?.samplePrice ?? 0.00;
                    }
                },
                {
                    field: 'sampleQuota', title: '名额', minWidth: 100, sort: true, align: 'center',
                    templet: function (d) {
                        return d.info?.sampleQuota ?? 0;
                    }
                },
                {
                    field: 'receiveQuota', title: '领取人数', minWidth: 120, sort: true, align: 'center',
                    templet: function (d) {
                        return d.info?.receiveQuota ?? 0;
                    }
                },
                {
                    field: 'samplePrice',
                    title: '完成率',
                    sort: true,
                    align: 'center',
                    minWidth: 120,
                    templet: function (d) {
                        let sampleQuota = d.info.sampleQuota;
                        let receiveQuota = d.info.receiveQuota;
                        if (!isNotNull(sampleQuota) || !isNotNull(receiveQuota)) {
                            return 0.00 + '%'
                        }
                        return Math.round(receiveQuota / sampleQuota * 10000) / 100 + "%";
                    }
                },
                {
                    field: 'evaluationNum',
                    title: '评价数',
                    minWidth: 120,
                    sort: true,
                    align: 'center',
                    templet: function (d) {
                        return d.samplesIndicators?.evaluationNum ?? 0;
                    }
                },
                {
                    field: 'evaluationRate', title: '评价率', minWidth: 120, sort: true, align: 'center',
                    templet: function (d) {
                        let receiveQuota = Math.floor(d.info?.receiveQuota ?? 0);
                        let evaluationNum = Math.floor(d.samplesIndicators?.evaluationNum ?? 0);
                        if (receiveQuota === 0) {
                            return 0 + '%'
                        }
                        return Math.round(evaluationNum / receiveQuota * 10000) / 100 + "%";
                    }
                },
                {
                    field: 'GradeANum', title: 'A级', minWidth: 100, sort: true, align: 'center',
                    templet: function (d) {
                        return d.samplesIndicators?.GradeANum ?? 0;
                    }
                },
                {
                    field: 'GradeBNum', title: 'B级', minWidth: 100, sort: true, align: 'center',
                    templet: function (d) {
                        return d.samplesIndicators?.GradeBNum ?? 0;
                    }
                },
                {
                    field: 'GradeCNum', title: 'C级', minWidth: 100, sort: true, align: 'center',
                    templet: function (d) {
                        return d.samplesIndicators?.GradeCNum ?? 0;
                    }
                },
                {
                    field: 'evaluationReward', title: '现金报酬', minWidth: 120, sort: true, align: 'center',
                    templet: function (d) {
                        return d.samplesIndicators?.evaluationReward ?? '0.00';
                    }
                },
                {
                    field: 'totalCouponAmount', title: '优惠券报酬', minWidth: 120, sort: true, align: 'center',
                    templet: function (d) {
                        return d.info.totalCouponAmount ?? 0;
                    }
                },
                {
                    field: 'createTime', title: '发布时间', minWidth: 150, sort: true, align: 'center',
                    templet: function (d) {
                        return d.info?.createTime;
                    }
                },
            ]],
            limits: [50, 100, 150, 200, 250, 300],
            limit: 50,
            page: true,
            request: {
                pageName: 'pageNum',
                limitName: 'pageSize'
            },
            response: { //定义后端 json 格式，详细参见官方文档
                statusName: 'code', //状态字段名称
                statusCode: '200', //状态字段成功值
                msgName: 'msg', //消息字段
                countName: 'total', //总数字段
                dataName: 'rows' //数据字段
            },
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // 执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });

        // 监听表格 行双击事件
        table.on('rowDouble(currentTableFilter)', function (obj) {
            let info = obj.data.info;
            var index = layer.open({
                title: '样品发放详情',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: './provideSamplesSub-list.html?mainId=' + info.id + '&subject=' + encodeURIComponent(info.subject),
            });
            $(window).on("resize", function () {
                layer.full(index);
            });

        });
    });

    /**
     * 重载表格数据
     */
    function reloadTable() {
        layui.use(['table'], function () {
            let table = layui.table;
            table.reload('currentTableId', {
                url: '/provide/samples/list'
            });
        })
    }

</script>

</body>
</html>